{% extends "base.html" %}
{% block title %}图书管理{% endblock %}
{% block body %}




<div class="container">
    <h1>图书列表</h1>
    <a href="{{ url_for('add_book') }}" class="btn btn-primary">添加图书</a>
    <table>
        <tr>
            <th>书名</th>
            <th>作者</th>
            <th>状态</th>
            <th>借阅者</th>
            <th>操作</th>
        </tr>
        {% for book in books %}
<tr>
<td>{{ book.title }} </td>
<td>{{ book.author }} </td>
<td>{{ '可借' if book.available else '不可借' }} </td>
<td>{{ book.borrower.name if book.borrower else '无' }} </td>
<td>
{% if book.available %}
<a href="{{ url_for('edit_book', book_id=book.id) }}" class="btn btn-secondary">编辑 </a>
<form action="{{ url_for('delete_book', book_id=book.id)}}" method="post" style="display:inline;">
<button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这本书吗？');">删除 </button>
</form>
{% else %}
<form action="{{ url_for('return_book', book_id=book.id)}}" method="post" style="display:inline;">
<button type="submit" class="btn btn-warning" onclick="return confirm('确定要归还这本书吗？');">归还 </button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}

<nav>
       <ul>
           <li><a href="{{ url_for('home') }}">首页</a></li>
           <li><a href="{{ url_for('books') }}" class="btn">图书管理</a></li>
           <li><a href="{{ url_for('search') }}" class="btn">搜索</a></li>
           <li><a href="{{ url_for('about') }}">关于</a></li>
           {% if current_user.is_authenticated %}
               <li><a href="{{ url_for('logout') }}">登出</a> </li>
                {% if current_user.is_authenticated %}
                       <li>欢迎, {{ current_user.email }} </li>
                   {% endif %}
           {% else %}
               <li><a href="{{ url_for('login') }}">登录</a> </li>
               <li><a href="{{ url_for('register') }}">注册</a> </li>
           {% endif %}
       </ul>
</nav>
